/**
 * 
 */
package org.t2.game.server.foundation.starting;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;


/**
 * @author YY
 *
 */
@Configuration
public class ApplicationSettings {
	private Set<Integer> serverIds;
	public Set<Integer> getGameServerIds() {
		if(serverIds == null) {
			Set<Integer> tempServerIds = new HashSet<>();
			//主服的服务器ID
			tempServerIds.add(gameServerId);
			//被合服的服务器ID
			tempServerIds.addAll(getSubServerIds());
			serverIds = tempServerIds;
		}
		return serverIds;
	}
	
	private Set<Integer> subServerIds;
	//获取附属（被合服）的服务器ID
	public Set<Integer> getSubServerIds() {
		if(subServerIds == null) {
			Set<Integer> temp = new HashSet<>();
			String[] parts = gameServerMergeIds.split(",");
			for(String part : parts) {
				int serverId = Integer.parseInt(part);
				if(serverId <= 0) {
					continue;
				}
				temp.add(serverId);
			}
			subServerIds = temp;
		}
		return subServerIds;
	}


	//#游戏服务器ID
	@Value("${game.server.id:5}")
	protected int gameServerId;
	//#合服ID列表
	@Value("${game.server.merge.ids:0,0,0}")
	protected String gameServerMergeIds;
	//#游戏平台ID
	@Value("${game.server.platformid:1001}")
	protected int gameServerPlatformid;
	//#游戏服务器端口
	@Value("${game.server.port:10005}")
	protected int gameServerPort;
	//#游戏服务器的tomcat端口
	@Value("${server.port:20005}")
	protected int serverPort;
	//#服务器开服方式，1启动服务器时间作为开服时间，2后台开服时间作为开服时间
	@Value("${game.open.type:1}")
	protected int gameOpenType;
	//#服务器是否调试模式
	@Value("${game.debug.mode:true}")
	protected boolean gameDebugMode;
	//#服务器netty空闲时间检测，0表示不检查空闲
	@Value("${game.netty.idle:60}")
	protected int gameNettyIdle;
	//#项目配置表格式
	@Value("${game.design.file.path:D:/Git/t2-server/design/export/server-ajson/}")
	protected String gameDesignFilePath;
	//#热更配置文件夹
	@Value("${game.fix.design.folder:/uploadfiles/design/}")
	protected String gameFixDesignFolder;
	//#后台加密秘钥
	@Value("${backstage.key:zhaizi_t2_2024}")
	protected String backstageKey;
	//#后台地址
	@Value("${backstage.url:http://127.0.0.1:9011}")
	protected String backstageUrl;
	//#渠道代号，默认other，mz、quicksdk
	@Value("${game.channel.code:quicksdk}")
	protected String gameChannelCode;
	//#日志输出格式配置
	@Value("${logging.config:file:./config/log4j2.xml}")
	protected String loggingConfig;
	//#数据库配置
	@Value("${database.config.file:file:./config/database.db}")
	protected String databaseConfigFile;


	public Set<Integer> getServerIds() {
		return serverIds;
	}
	public int getGameServerId() {
		return gameServerId;
	}
	public String getGameServerMergeIds() {
		return gameServerMergeIds;
	}
	public int getGameServerPort() {
		return gameServerPort;
	}
	public int getServerPort() {
		return serverPort;
	}
	public int getGameOpenType() {
		return gameOpenType;
	}
	public String getBackstageKey() {
		return backstageKey;
	}
	public String getBackstageUrl() {
		return backstageUrl;
	}
	public String getLoggingConfig() {
		return loggingConfig;
	}
	public String getDatabaseConfigFile() {
		return databaseConfigFile;
	}
	public String getGameChannelCode() {
		return gameChannelCode;
	}
	public int getGameServerPlatformid() {
		return gameServerPlatformid;
	}
	public boolean isGameDebugMode() {
		return gameDebugMode;
	}
	public int getGameNettyIdle() {
		return gameNettyIdle;
	}
	public String getGameDesignFilePath() {
		return gameDesignFilePath;
	}
	public String getGameFixDesignFolder() {
		return gameFixDesignFolder;
	}
}
